import { transFormData } from '@/utils'
import { getDepartmentsInfo } from '@/api/departments'

const getDefaultState = () => {
  return {
    data: []
  }
}
const state = getDefaultState()
const mutations = {
  updateDepInfo(state, data) {
    state.data = transFormData(data.depts, { id: 'id', pid: 'pid' })
  }
}
const actions = {
  // 获取部门信息
  async getDepartmentInfo({ commit }) {
    const res = await getDepartmentsInfo()
    if (res.success) {
      const data = res.data
      commit('updateDepInfo', data)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
